---@class GT.ui.control.button : GT.ui
---@field u table<RoleID,GT.ui.control.button> 玩家独立数据驱动
---@field binding GT.ui.control.button
GT.ui.control.button = class(GT.ui, false)

---@class ui_data_button : ui_data
---@field img Int32 图片  --动态绑定值 通过对象.binding.img 动态修改数据
---@field is_open bool 是否开启多态
---@field suspend_image number 悬浮状态下图片
---@field press_image number 按下状态下图片


--- 创建按钮
---@param data ui_data_button
---@return GT.ui.control.button
function GT.ui.control.button:ctor(data)
    data.class=GT.ui.control.button
    if data.uid ~= nil then
        super(self, data)
    else
        data.u_type = GT.ui.type.button
        self.img = data.img
        self.is_open=data.is_open
        self.suspend_image=data.suspend_image
        self.press_image=data.press_image
        --创建控件
        super(self, data)
        --设置图片
        if data.img~=nil then
            self:set_image(self.img)
        end
        if data.is_open~=nil then
            self:set_bar_status(self.is_open)
        end
        if data.suspend_image~=nil then
            self:set_suspend_image(self.suspend_image)
        end
        if data.press_image~=nil then
            self:set_press_image(self.press_image)
        end
    end

    self:button_watch()
    return self
end


---转对象
---@param data ui_data_button
---@return GT.ui.control.button
function GT.ui.control.button.obj(data)
    return new(GT.ui.control.button, data)
end

--监听绑定
---@return GT.ui.control.button
function GT.ui.control.button:button_watch()
    ---@type bind_data[]
    local data = {
        {
            key = "img",
            func = function(val, old)
                self.img = val
                self:set_image(self.img)
            end
        },
        {
            key = "is_open",
            func = function(val, old)
                self.is_open = val
                self:set_bar_status(self.is_open)
            end
        },
        {
            key = "suspend_image",
            func = function(val, old)
                self.suspend_image = val
                self:set_suspend_image(self.suspend_image)
            end
        }
        ,
        {
            key = "press_image",
            func = function(val, old)
                self.press_image = val
                self:set_press_image(self.press_image)
            end
        }
        
    }
    self.bind:add(data)
    return self
end

-- --- 销毁
-- ---@return GT.ui.control.button
-- function GT.ui.control.button:dtor()
--     self = nil
--     return self
-- end

--- 设置按钮快捷键
---@param btn Int32 按键ID
---@return GT.ui.control.button
function GT.ui.control.button:set_short_cut(btn)
    game_api.set_btn_short_cut(self.player.player, self.uid, btn)
    return self
end

--- 设置按钮辅助键
---@param btn Int32 按键ID
---@return GT.ui.control.button
function GT.ui.control.button:set_func_short_cut(btn)
    game_api.set_btn_func_short_cut(self.player.player , self.uid, btn)
    return self
end

--- 设置ui按钮是否开启多态
---@param is_open Bool 是否开启
---@return GT.ui.control.button
function GT.ui.control.button:set_bar_status(is_open)
    game_api.set_ui_comp_bar_status(self.player.player , self.uid, is_open)
    return self
end

--- 设置ui组件图片(图片类型)
---@param image_id Texture 图片
---@return GT.ui.control.button
function GT.ui.control.button:set_image_with_icon(image_id)
    game_api.set_ui_comp_image_with_icon(self.player.player , self.uid, image_id)
    return self
end

--- 设置ui组件图片
---@param image_id Int32 图片id
---@return GT.ui.control.button
function GT.ui.control.button:set_image(image_id)
    game_api.set_ui_comp_image(self.player.player , self.uid, image_id)
    return self
end

--- 播放/停止技能按钮激活动效
---@param play Bool 播放/停止
---@return GT.ui.control.button
function GT.ui.control.button:set_skill_effect(play)
    game_api.set_skill_btn_action_effect(self.player.player , self.uid, play)
    return self
end

--- 设置ui组件悬浮态图片
---@param image_id Int32 图片id
---@return GT.ui
function  GT.ui.control.button:set_suspend_image(image_id)
    game_api.set_ui_comp_suspend_image(self.player.player, self.uid, image_id)
    return self
end

--- 设置ui组件按下态图片
---@param role Role 玩家
---@param comp_name Str 控件名
---@param image_id Int32 图片id
function  GT.ui.control.button:set_press_image(image_id)
    game_api.set_ui_comp_press_image(self.player.player, self.uid, image_id)
    return self
end

--- 设置ui组件禁用态图片
---@param role Role 玩家
---@param comp_name Str 控件名
---@param image_id Int32 图片id
function GT.ui.control.button:set_disabled_image(image_id)
    game_api.set_ui_comp_disabled_image(self.player.player, self.uid, image_id)
    return self
end